    ### DATAPACK CREATED BY: ...standing on the shoulders of giants...###

...no really...

##################
# INFERNALDEVICE #
##################
Seriously, this pack wouldn't have been possible without their extensive informative support. Their youtube videos and accompanying datapacks have made projects like this possible. Without them, it would still be stuck in one of the many "Ask 4 Help" forums. Please, check out InfernalDevice's work at their youtube channel: https://www.youtube.com/@InfernalDevice I'm more than willing to wager, you'll learn something not just new, but useful to your datapack ambitions!

#############
# GALSERGEY #
#############
The other giant, whose brain has been picked through the years of reddit posts/comments/responses is GalSergy. You can find their irreplaceable information on reddit: https://www.reddit.com/user/GalSergey/

###############################
# Various Communities & Tools #
###############################
In no particular order: https://mcstacker.net/  https://www.reddit.com/r/MinecraftCommands/  https://misode.github.io/  Cloud Wolf MC's discord community:https://discord.gg/VbsGPB3xmz  https://datapack.wiki/  https://minecraft.wiki/  https://www.plotz.co.uk/ (Amaing that site is still goin' strong!)

A *massive*...

 /$$$$$$$$ /$$   /$$  /$$$$$$  /$$   /$$ /$$   /$$       /$$     /$$ /$$$$$$  /$$   /$$
|__  $$__/| $$  | $$ /$$__  $$| $$$ | $$| $$  /$$/      |  $$   /$$//$$__  $$| $$  | $$
   | $$   | $$  | $$| $$  \ $$| $$$$| $$| $$ /$$/        \  $$ /$$/| $$  \ $$| $$  | $$
   | $$   | $$$$$$$$| $$$$$$$$| $$ $$ $$| $$$$$/          \  $$$$/ | $$  | $$| $$  | $$
   | $$   | $$__  $$| $$__  $$| $$  $$$$| $$  $$           \  $$/  | $$  | $$| $$  | $$
   | $$   | $$  | $$| $$  | $$| $$\  $$$| $$\  $$           | $$   | $$  | $$| $$  | $$
   | $$   | $$  | $$| $$  | $$| $$ \  $$| $$ \  $$          | $$   |  $$$$$$/|  $$$$$$/
   |__/   |__/  |__/|__/  |__/|__/  \__/|__/  \__/          |__/    \______/  \______/ 

...to all of those mentioned! (Font made using https://patorjk.com/software/taag/)

#########################################################################################################################

    ##############################
    ## HOW TO USE THIS DATAPACK ##
    ##############################
## Teach Master level Librarians max level enchantments: ##
- Bring the maximum level enchantment you want, to a 'MASTER' level 'LIBRARIAN' to sell. 'RIGHT CLICK' on this 'LIBRARIAN'. 
!NOTE: The Librarian trade GUI must be exited before the learned trade will appear!

!⯀!NOTE: ONLY ONE ENCHANTMENT CAN BE LEARNED AT A TIME. IF THERE ARE MULTIPLE ENCHANTMENTS ON A SINGLE ENCHANTED BOOK, ONLY THE MAXIMUM LEVEL ENCHANTMENT WITH THE EARLIEST APPEARANCE IN AN ALPHABETICAL ORDERED LIST WILL BE LEARNED. ALL OTHER ENCHANTMENTS WILL BE DELETED.CURSES ARE AFTER THE ENTIRE ALPHABET!⯀!

###########################################################################################################################################

    #############################
    ### TEACHING ENCHANTMENTS ###
    #############################
This system enables Master level Librarians, to learn & sell maximum level enchantments, such as Sharpness V, Unbreaking III, etc. But not enchantments such as Lure II and Fire Aspect I, as those are not the maximum possible level for them.

!⯀!NOTE: This system doesn't run, until the 'Organized Master Villager Trades' system operates on the targeted master Librarian. This is done to prevent taught trades from being deleted.!⯀!


    #############################
    # How this is accomplished: #
1: An advancement 'teach_librarian_advancement' detects when a player, holding an enchanted book, right clicks on a Master level Librarian.

2. Reward function 'teach_librarian_reward_tutor_raycast_setup' then does a bunch of work: Remove the triggering advancement > Tags the Player who triggered the advancement as 'TUTOR' > Sets the 'steps' for the ray cast to 33 (3.3 blocks is the interaction distance) > runs the actual raycast operation function 'tutor_raycast_operation' which identifies if the player is looking at villager, and if so runs 'tutor_raycast_success' which tags the targeted villager with 'PUPIL_LIBRARIAN'.

3. After the ray cast has tagged the librarian in question, function 'enchantment_lesson_select' is ran. This checks the book in the hand of the player, to see what maximum enchantment exists on the enchanted book. 
!!!NOTE: ONLY ONE ENCHANTMENT CAN BE LEARNED AT A TIME. IF THERE ARE MULTIPLE ENCHANTMENTS ON A SINGLE ENCHANTED BOOK, ONLY THE MAXIMUM LEVEL ENCHANTMENT WITH THE EARLIEST APPEARANCE IN AN ALPHABETICAL ORDERED LIST WILL BE LEARNED. ALL OTHER ENCHANTMENT WILL BE DELETED.CURSES ARE AFTER THE ENTIRE ALPHABET!!!

4. If the max level enchantment is found, AND the selected villager hasn't already learned this enchantment, then the function '<enchantment>_<max level>_lesson' runs.

5. '<enchantment>_<max level>_lesson' then adds, to the end of the current list of trades offered by the targeted Master Librarian, the specified enchantment. The prices are determined by the level, and if the enchantment is considered a 'treasure'. (Lvl 1 = 5 Emeralds, Lvl 2 = 8, Lvl 3 = 11, Lvl 4 = 14, Lvl 5 = 17, Treasure = 2x Lvl cost). The player held enchanted book is deleted, and a 'Villager celebrates' sound is played to the player.

!⯀!NOTE: The prices can be edited by replacing the value located between the '<>' in the following command: 'data modify entity @s Offers.Recipes append value {maxUses:<#>,priceMultiplier:0.2f,buy:{id:"minecraft:emerald",count:<#>},buyB:{id:"minecraft:book",count:<#>},sell:{id:"minecraft:enchanted_book",count:1,components:{"minecraft:stored_enchantments":{"minecraft:<enchantment>":<level #>}}}}'!⯀!


####################
Thank you again to all who made this 2011 dream a reality. With this complete system, the tedious grind is no more. Now, there's an exciting incentive to go fishing, use an enchanting table, and explore the world - excited for the contents of every treasure chest! (Jungle Pyramids, Strongholds, Dungeons, Mineshafts, Ancient Cities, Desert Pyramids, Pillager Outposts, Ocean Ruins, Trial Chambers, Bastion Remnants, and Woodland Mansions!) And no more need to infinitely expand the world file size seeking out the 20th Trial Chamber or Ancient City so everyone can get 'Wind Charge III' and 'Swift Sneak III'!

#######################################################################################################################